package com.wang.controller;

import com.wang.dao.AddUser;
import com.wang.entity.User;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.swing.*;
import java.io.IOException;
import java.io.PrintWriter;

public class AddUserServlet extends HttpServlet {
    private AddUser addUser = new AddUser();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//        resp.setContentType("text/html");
//        req.setCharacterEncoding("utf-8");//get其实不用这个
        String username = (String) req.getParameter("username");
        String password = (String) req.getParameter("password");
        User user = new User(null, username, password, 0);
        int i = addUser.addUser(user);
        if(i==1){
            System.out.println("添加用户成功");
            req.getRequestDispatcher("/login.jsp").forward(req,resp);
        }
        else{
            System.out.println("注册失败");
        }
    }
}
